package com.code.day21;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class DemoClient {
    public static void main(String[] args) throws Exception {
        //建立socket对象 设置端口号
        Socket socket = new Socket("127.0.0.1", 9999);
        //建立输出流 发送数据请求
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("你好我叫刘大胆".getBytes());
        //建立输入流 接收数据
        InputStream inputStream = socket.getInputStream();
        byte[] bytes = new byte[1024];
        int len = inputStream.read(bytes);
        System.out.println(new String(bytes, 0, len));
        //关流
        inputStream.close();
        outputStream.close();
        socket.close();
    }
}
